package com.frogs.ucenter.v1.request;

import javax.servlet.http.HttpServletRequest;

import com.frogs.framework.util.StringUtil;
import com.frogs.framework.web.HttpRequestInfo;
import com.frogs.system.util.ApiUrlParamEnum;
import com.frogs.system.web.api.request.Request;
import com.frogs.system.web.exception.RequestIllegalException;

/**
 * 校验消费验证码请求参数类
 *
 * @author hongyuhao
 * 
 */
public class SmsVerifyConsumeCodeRequest extends Request {
	
	private static final long serialVersionUID = 7452302262076565812L;

	private String phone;
	
	private Integer userId;
	
	private String code;
	
	public SmsVerifyConsumeCodeRequest() {
	}
	
	@Override
	public void parse(HttpServletRequest request) {
		HttpRequestInfo requestInfo = new HttpRequestInfo(request);
		
		this.phone = requestInfo.getParameter(ApiUrlParamEnum.phone.getParamName(), "");
		this.userId = requestInfo.getIntParameter(ApiUrlParamEnum.userId.getParamName(), 0);
		this.code = requestInfo.getParameter(ApiUrlParamEnum.code.getParamName());
		if (!StringUtil.isMobilePhone(phone)) {
			throw new RequestIllegalException("请输入正确的手机号");
		}
		if(StringUtil.isEmpty(code)) {
			throw new RequestIllegalException("请输入验证码");
		}
		if (userId < 1) {
			throw new RequestIllegalException("userId error " + userId);
		}
	}
	
	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public Integer getUserId() {
		return userId;
	}

	public void setUserId(Integer userId) {
		this.userId = userId;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}
	
	

}
